package com.nebula.tlggoods.controller;

import com.nebula.tlggoods.entity.CollectCondition;
import com.nebula.tlggoods.service.CollectService;
import com.nebula.tlggoods.tools.Record;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 收藏控制层
 */
@RestController
public class CollectController {

    @Resource
    private CollectService collectService;

    /**
     * 收藏商品，收藏店铺
     *
     * @param collectCondition 条件对象
     * @return
     */
    @PostMapping("/addCollect")
    @ApiOperation(notes = "收藏商品、店铺", value = "收藏商品、店铺")
    public Record addCollect(@RequestBody CollectCondition collectCondition) {
        return collectService.addCollect(collectCondition.getUserId(), collectCondition.getCollectType(), collectCondition.getObjectId());
    }

    /**
     * 取消收藏
     *
     * @param collectCondition 条件对象
     * @return
     */
    @PutMapping("/cancelCollect")
    @ApiOperation(notes = "取消收藏", value = "取消收藏")
    public Record cancelCollect(@RequestBody CollectCondition collectCondition) {
        return collectService.cancelCollect(collectCondition.getUserId(), collectCondition.getCollectType(), collectCondition.getObjectId());
    }

    /**
     * 判断商品、店铺是否已经收藏
     *
     * @param userId      用户id
     * @param collectType 收藏类型 0商品，1店铺
     * @param objectId    收藏对象的id
     * @return
     */
    @GetMapping("/isCollect")
    @ApiOperation(notes = "判断商品、店铺是否已被收藏", value = "判断商品、店铺是否已被收藏")
    public Record isCollect(Integer userId, Integer collectType, Integer objectId) {
        return collectService.isCollect(userId, collectType, objectId);
    }


}
